package com.koron.ticket.work.logicticket.ycpowerlinesecond;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.koron.bean.base.Response;
import com.koron.bean.workflow.RedirectQuery;
import com.koron.common.core.util.CodeTools;
import com.koron.common.core.util.FastJsonUtils;
import com.koron.ticket.utils.StringUtils;
import com.koron.ticket.work.common.bean.TicketBaseMsg;
import com.koron.ticket.work.common.service.FifteenTablesService;
import com.koron.ticket.work.common.service.YcCommonService;
import com.koron.ticket.work.enums.PrintTemplate;
import com.koron.ticket.work.enums.TicketNodeStatus;
import com.koron.ticket.work.enums.TicketStatus;
import com.koron.ticket.work.enums.WorkFlowType;
import com.koron.ticket.work.logicticket.hightask.bean.HighTaskDto;
import com.koron.ticket.work.logicticket.ychotsafework.bean.HeatAnalysisBean;
import com.koron.ticket.work.logicticket.ychotsafework.mapper.HeatAnalysisBeanMapper;
import com.koron.ticket.work.logicticket.ycpowerlinesecond.bean.AcceptDto;
import com.koron.ticket.work.logicticket.ycpowerlinesecond.bean.YcLineSecondDto;
import com.koron.ticket.work.logicticket.ycpowerlinesecond.bean.YcLineSecondPrint;
import com.koron.ticket.work.workPermit.bean.WorkPermit;
import com.koron.ticket.work.workPermit.service.WorkPermitService;
import com.koron.ticket.work.workend.bean.WorkEnd;
import com.koron.ticket.work.workflow.bean.WorkFlow;
import com.koron.ticket.work.workflow.service.WorkFlowService;
import com.koron.ticket.work.workmember.bean.WorkMember;
import com.koron.ticket.work.workteam.bean.WorkTeam;
import com.koron.ticket.work.workticket.bean.WorkTicket;
import com.koron.ticket.work.workticket.service.WorkTicketService;
import com.koron.ticket.work.workyccontent.bean.YcContentBean;
import com.koron.ticket.work.workyccontent.service.YcContentService;
import com.koron.ticket.work.workycinfo.bean.TicketYcInfoBean;
import com.koron.ticket.work.workycinfo.service.WorkYcInfoService;
import com.koron.ticket.workchange.ticketchange.bean.TicketChange;
import com.koron.ticket.workchange.ticketchange.service.TicketChangeService;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Collectors;

@Service
public class YcLineSecondService {

    @Autowired
    private FifteenTablesService fifteenTablesService;

    @Autowired
    private WorkFlowService workFlowService;

    @Autowired
    private WorkTicketService workTicketService;

    @Autowired
    private WorkPermitService workPermitService;

    @Autowired
    private WorkYcInfoService workycinfoservice;

    @Autowired
    private YcCommonService yccommonservice;

    @Autowired
    private YcContentService yccontentservice;

    @Autowired
    private TicketChangeService ticketChangeService;

    @TaskAnnotation("writeSave")
    public Response writeSave(SessionFactory factory, YcLineSecondDto dto) {
        workTicketService.checkTimeOut(factory, dto.getId(), dto.getUpdateTime());//检查信息是否过期
        String id = CodeTools.getCode32();

        // 工作票主表
        WorkTicket workticket = Convert.convert(WorkTicket.class, dto);
        // 线路二种作业票
        TicketYcInfoBean ticketycinfobean = Convert.convert(TicketYcInfoBean.class, dto);
        // 工作票基础信息
        TicketBaseMsg ticketbasemsg = Convert.convert(TicketBaseMsg.class, dto);

        ticketycinfobean.setTicketType(workticket.getType());
        if (StrUtil.isNotBlank(workticket.getId())) {
            workTicketService.update(factory, workticket);
            ticketycinfobean.setWorkTicketId(workticket.getId());
        } else {
            workticket.setId(id);
            ticketycinfobean.setWorkTicketId(id);
            workTicketService.insert(factory, workticket);
        }
        workycinfoservice.save(factory, ticketycinfobean);
        yccontentservice.save(factory, dto.getContentlist(), workticket.getId(), PrintTemplate.YcPowerLineSecond.getType());

        // 更新工作票基础信息
        yccommonservice.updateTicketMsg(factory, workticket.getId(), ticketbasemsg);

        return Response.success(workticket.getId());
    }


    @TaskAnnotation("writeSubmit")
    public Response writeSubmit(SessionFactory factory, HighTaskDto dto) {
        WorkTicket workticket = Convert.convert(WorkTicket.class, dto);
        String workTicketId = yccommonservice.ycWriteSubmitByWorkFlowType(factory, workticket, WorkFlowType.HighTaskTicketWork.getWorkFlow());
        return Response.success(workTicketId);
    }

    @TaskAnnotation("signSave")
    public Response signSave(SessionFactory factory, AcceptDto dto) {
        workTicketService.checkTimeOut(factory, dto.getWorkTicketId(), dto.getUpdateTime());//检查信息是否过期
        String workTicketId = dto.getWorkTicketId();
        List<WorkFlow> workFlowList = dto.getWorkFlowList();
        workFlowList.stream().forEach(w->w.setWorkTicketId(workTicketId));

        // 删除签名表签发节点的签名
        workFlowService.deleteByWorkTicketId(factory, dto.getWorkTicketId(), TicketStatus.SIGN.getStatus());
        workFlowService.batchInsert(factory, workFlowList);

        return Response.success("提交/保存成功");
    }

//    @TaskAnnotation("countersignSave")
//    public Response countersignSave(SessionFactory factory, WorkFlow workFlow) {
//        yccommonservice.countersignSave(factory, workFlow);
//        return Response.success("提交/保存成功");
//    }

    @TaskAnnotation("acceptSave")
    public Response acceptSave(SessionFactory factory, AcceptDto dto) {
        workTicketService.checkTimeOut(factory, dto.getWorkTicketId(), dto.getUpdateTime());//检查信息是否过期
        String workTicketId = dto.getWorkTicketId();
        List<WorkFlow> workFlowList = dto.getWorkFlowList();

        TicketYcInfoBean ticketycinfobean = new TicketYcInfoBean();
        ticketycinfobean.setWorkTicketId(dto.getWorkTicketId());
        ticketycinfobean.setWorkStartTime(dto.getWorkStartTime());
        ticketycinfobean.setWorkEndTime(dto.getWorkEndTime());

        // 更新工作开始完成日期
        workycinfoservice.updateSelective(factory, ticketycinfobean);

        // 删除签名表许可节点的签名
        workFlowService.deleteByWorkTicketId(factory, dto.getWorkTicketId(), TicketStatus.ACCEPT.getStatus());
        workFlowService.batchInsert(factory, workFlowList);
        return Response.success("提交/保存成功");
    }

    @TaskAnnotation("permitSave")
    public Response permitSave(SessionFactory factory, WorkPermit workPermit) {
        yccommonservice.permitSave(factory, workPermit);
        return Response.success("待许可-提交/保存成功");
    }

    @TaskAnnotation("ticketEndSave")
    public Response ticketEndSave(SessionFactory factory, WorkEnd workend) {
        String workTicketId = workend.getWorkTicketId();
        TicketYcInfoBean ycinfo = new TicketYcInfoBean();
        ycinfo.setWorkTicketId(workTicketId);
        ycinfo.setRemark(workend.getRemark());

        workFlowService.deleteByWorkTicketId(factory, workTicketId, TicketStatus.TICKET_END.getStatus());
        if (CollUtil.isNotEmpty(workend.getWorkFlowList())) {
            workend.getWorkFlowList().stream().forEach(w->w.setWorkTicketId(workTicketId));
            workFlowService.batchInsert(factory, workend.getWorkFlowList());
        }

        workycinfoservice.updateSelective(factory, ycinfo);

        return Response.success("待许可-提交/保存成功");
    }

//    @TaskAnnotation("ticketEndSave")
//    public Response ticketEndSubmitOrSave(SessionFactory factory, WorkEnd workEnd) {
//        List<WorkFlow> workFlowList = workEnd.getWorkFlowList();
//        workFlowService.batchInsert(factory, workFlowList);
//        return Response.success("工作票待终结-提交/保存成功");
//    }

    @TaskAnnotation("workflowUpdate")
    public Response workflowUpdate(SessionFactory factory, RedirectQuery redirectQuery) throws ParseException {
        Integer operation = redirectQuery.getOperation();
        String workTicketId = redirectQuery.getDataId();
        WorkTicket workTicket = workTicketService.queryById(factory, workTicketId);
        // 提交前状态
        Integer status = workTicket.getStatus();
        String type = workTicket.getType();

        // 1. 如果被驳回，返回对应状态，仅删除签名的数据，其他的数据不做处理
        if (operation == 1) {
            String rejectNodeCode = redirectQuery.getRejectNodeCode();
            rejectNodeCode = rejectNodeCode.replace("call-", "");
            if (rejectNodeCode.equals(TicketNodeStatus.WRITE.getNodeName())) {
                Integer rejectStatus = TicketStatus.WRITE.getStatus();
                fifteenTablesService.clenWorkFlowByStatus(factory, workTicketId, rejectStatus);
                workPermitService.deleteByWorkTicketId(factory, workTicketId);//删除许可信息
                workTicket.setStatus(rejectStatus);
            } else if (rejectNodeCode.equals(TicketNodeStatus.SIGN.getNodeName())) {
                Integer rejectStatus = TicketStatus.SIGN.getStatus();
                fifteenTablesService.clenWorkFlowByStatus(factory, workTicketId, rejectStatus);
                workPermitService.deleteByWorkTicketId(factory, workTicketId);//删除许可信息
                workTicket.setStatus(rejectStatus);
            } else if (rejectNodeCode.equals(TicketNodeStatus.COUNTERSIGN.getNodeName())) {
                Integer rejectStatus = TicketStatus.COUNTERSIGN.getStatus();
                fifteenTablesService.clenWorkFlowByStatus(factory, workTicketId, rejectStatus);
                workPermitService.deleteByWorkTicketId(factory, workTicketId);//删除许可信息
                workTicket.setStatus(rejectStatus);
            } else if (rejectNodeCode.equals(TicketNodeStatus.ACCEPT.getNodeName())) {
                Integer rejectStatus = TicketStatus.ACCEPT.getStatus();
                fifteenTablesService.clenWorkFlowByStatus(factory, workTicketId, rejectStatus);
                workPermitService.deleteByWorkTicketId(factory, workTicketId);//删除许可信息
                workTicket.setStatus(rejectStatus);
            } else if (StrUtil.contains(rejectNodeCode, TicketNodeStatus.PERMIT.getNodeName())) {
                // 高处作业有两个许可，平台返回的code 包含PERMIT都认为是许可节点
                Integer rejectStatus = TicketStatus.PERMIT.getStatus();
                fifteenTablesService.clenWorkFlowByStatus(factory, workTicketId, rejectStatus);
                // 20211111: 如何是待许可状态，讲预览标志设置成未预览
                workTicket.setPreviewFlag(1);
                workTicket.setStatus(rejectStatus);
            } else if (rejectNodeCode.equals(TicketNodeStatus.WORK_END.getNodeName())) {
                Integer rejectStatus = TicketStatus.WORK_END.getStatus();
                fifteenTablesService.clenWorkFlowByStatus(factory, workTicketId, rejectStatus);
                workTicket.setStatus(rejectStatus);
            }
            workTicketService.update(factory, workTicket);
        } // 2. 如果通过，工作票进入下一个状态，并根据状态的不同进行不同的操作
        else if (operation == 32) {
            // 下一个节点编码
            String curNodeCode = redirectQuery.getCurNodeCode();
            curNodeCode = curNodeCode.replace("call-", "");
            String formVariables = redirectQuery.getFormVariables();
            if (status.equals(TicketStatus.WRITE.getStatus())) {
                workTicket.setStatus(2);
            }
            // 2.1 如果是签发状态，保存签名信息
            if (status.equals(TicketStatus.SIGN.getStatus())) {
                // 保存许可信息
                AcceptDto accdto = JSONObject.parseObject(formVariables, AcceptDto.class);
                workFlowService.deleteByWorkTicketId(factory, workTicketId, TicketStatus.SIGN.getStatus());
                workFlowService.batchInsert(factory, accdto.getWorkFlowList());
                // 生成工作票号
                if (StrUtil.isBlank(workTicket.getCode())) {
                    String code = fifteenTablesService.getLastCodeByUnitAndTicketTypeNew(factory, workTicket.getUnit(), type);
                    if (StringUtils.isEmpty(code)) {
                        return Response.fail("工作票票号生成有问题，请联系运维人员");
                    }
                    workTicket.setCode(code);
                }
                workTicket.setStatus(4);//放弃自增控制，改为手动控制
            }
            else if (status.equals(TicketStatus.ACCEPT.getStatus())) {
                // 保存签名信息
                fifteenTablesService.saveWorkFLow(factory, formVariables);
                AcceptDto acceptdto = JSONObject.parseObject(formVariables, AcceptDto.class);
                this.acceptSave(factory, acceptdto);
                workTicket.setStatus(7);//放弃自增控制，改为手动控制
            }
            // 2.4 如果是待许可状态，保存签名信息，以及待许可信息
//            else if (status.equals(TicketStatus.PERMIT.getStatus())) {
//                // 保存许可信息
//                WorkPermit workPermit = JSONObject.parseObject(formVariables, WorkPermit.class);
//                // 保存签名信息
//                List<WorkFlow> workFlowList = workPermit.getWorkFlowList();
//                if (CollUtil.isNotEmpty(workFlowList)) {
//                    for (WorkFlow workFLow : workFlowList) {
//                        workFlowService.save(factory, workFLow);
//                    }
//                }
//                workTicket.setStatus(7);//放弃自增控制，改为手动控制
//            }
//            else if (status.equals(TicketStatus.WORK_END.getStatus())) {
//                WorkEnd workend = FastJsonUtils.getJsonToBean(formVariables, WorkEnd.class);
//                List<WorkFlow> workFlowList = workend.getWorkFlowList();
//                for (WorkFlow workFlow : workFlowList) {
//                    workFlowService.save(factory, workFlow);
//                }
//                workTicket.setStatus(7);//放弃自增控制，改为手动控制
//            }
            workTicketService.update(factory, workTicket);
        } else if (operation == 256) {
            Integer rejectStatus = TicketStatus.WRITE.getStatus();
            fifteenTablesService.clenWorkFlowByStatus(factory, workTicketId, rejectStatus);
            workPermitService.deleteByWorkTicketId(factory, workTicketId);//删除许可信息
            workTicket.setStatus(rejectStatus);
            workTicketService.update(factory, workTicket);
        } else {
            return Response.fail("操作类型为：" + operation + ",请联系运维人员");
        }

        return Response.success("提交成功");
    }

    @TaskAnnotation("workflowUpdateEnd")
    public Response workflowUpdateEnd(SessionFactory factory, RedirectQuery redirectQuery) throws ParseException {
        String formVariables = redirectQuery.getFormVariables();
        WorkEnd workend = FastJsonUtils.getJsonToBean(formVariables, WorkEnd.class);
        List<WorkFlow> workFlowList = workend.getWorkFlowList();
        for (WorkFlow workFlow : workFlowList) {
            workFlowService.save(factory, workFlow);
        }
//        fifteenTablesService.saveWorkFLow(factory, formVariables);
        WorkTicket workticket = new WorkTicket();
        workticket.setId(workend.getWorkTicketId());
        workticket.setStatus(8);
        workTicketService.update(factory, workticket);

        TicketYcInfoBean ycinfo = new TicketYcInfoBean();
        ycinfo.setWorkTicketId(workend.getWorkTicketId());
        ycinfo.setRemark(workend.getRemark());
        workycinfoservice.updateSelective(factory, ycinfo);
        return Response.success("工作票已归档", workend.getId());
    }

    @TaskAnnotation("workflowUpdateCancel")
    public Response workflowUpdateCancel(SessionFactory factory, RedirectQuery redirectQuery) {
        fifteenTablesService.workflowUpdateCancel(factory, redirectQuery);
        return Response.success("工作票已作废");
    }

    public void deleteById(SessionFactory factory, String id) {
        fifteenTablesService.deleteById(factory, id);
    }

    /**
     * 详情
     * @param factory
     * @param id
     * @return
     */
    public YcLineSecondDto getById(SessionFactory factory, String id) {
        // 主表
        WorkTicket workTicket = workTicketService.queryById(factory, id);
        // 工作票基础信息
        TicketBaseMsg ticketBaseMsg = yccommonservice.queryTicketMsg(factory, id);
        // 高处票基础信息
        TicketYcInfoBean ycInfo = workycinfoservice.getYcInfo(factory, id);
        // 签名信息
        List<WorkFlow> workFlows = workFlowService.queryByTicketId(factory, id);
        // 工作内容
        List<YcContentBean> ycInfolist = yccontentservice.getYcInfolist(factory, id);

        List<HeatAnalysisBean> heatAnalysisBeans = factory.getMapper(HeatAnalysisBeanMapper.class).queryByWorkTicketId(id);

        YcLineSecondDto dto = new YcLineSecondDto();
        BeanUtil.copyProperties(workTicket, dto);
        BeanUtil.copyProperties(ticketBaseMsg, dto);
        BeanUtil.copyProperties(ycInfo, dto);
//        dto.setHeatanAlysislist(heatAnalysisBeans);
        dto.setId(workTicket.getId());
        dto.setWorkFlowList(workFlows);
        dto.setContentlist(ycInfolist);

        TicketChange ticketChange = ticketChangeService.getByWorkTicketId(factory, id);
        dto.setTicketChange(ticketChange);
        return dto;
    }


    /**
     * 高处作业票、动火安全作业票
     * 获取打印数据
     *
     * @param factory
     * @param ticketId
     * @return
     */
    @TaskAnnotation("getPrintData")
    public List<YcLineSecondPrint> getPrintData(SessionFactory factory, String ticketId) {
        List<YcLineSecondPrint> printlist = new ArrayList();

        // 作业类别字典
//        Map<String, String> dataDictByCode = DataDictTool.getDataDictByCode("twoTicketManagement", "ticket_task_type");

        // 主表信息
        WorkTicket workTicket = workTicketService.queryById(factory, ticketId);
        // 水司信息
        TicketYcInfoBean ycInfo = workycinfoservice.getYcInfo(factory, ticketId);
        // 所有签名信息
        List<WorkFlow> workFlowlist = workFlowService.queryByTicketId(factory, ticketId);
        // 基础信息
        TicketBaseMsg ticketBaseMsg = yccommonservice.queryTicketMsg(factory, ticketId);
        String workDeptStr = "";
        String memberNameStr = "";
        // 工作票状态
        Integer status = workTicket.getStatus();
        // 工作班组、作业单位
        if (CollUtil.isNotEmpty(ticketBaseMsg.getWorkTeamList())) {
            workDeptStr = ticketBaseMsg.getWorkTeamList().stream().map(WorkTeam::getWorkTeamName).collect(Collectors.joining(","));
        }
        // 工作班组成员、作业人
        if (CollUtil.isNotEmpty(ticketBaseMsg.getWorkMemberList())) {
            memberNameStr = ticketBaseMsg.getWorkMemberList().stream().map(WorkMember::getMemberName).collect(Collectors.joining(","));
        }

        YcLineSecondPrint yclinesecondprint = new YcLineSecondPrint();
        yclinesecondprint.setUnitName(workTicket.getUnitName());
        yclinesecondprint.setDirectorName(workTicket.getDirectorName());
        yclinesecondprint.setPowerNameDouble(ycInfo.getPowerNameDouble());
        yclinesecondprint.setCode(workTicket.getCode());
        // 安全措施
        yclinesecondprint.setSafetyMsg(ycInfo.getSafetyMsg());
        yclinesecondprint.setRemark(ycInfo.getRemark());

        // 工作班组
        yclinesecondprint.setWorkTeamStr(workDeptStr);
        // 工作成员
        yclinesecondprint.setWriteWorkMemberStr(memberNameStr);

        yclinesecondprint.setEstimatedStartTime(DateUtil.format(workTicket.getEstimatedStartTime(), "yyyy年MM月dd日 HH时mm分"));
        yclinesecondprint.setEstimatedEndTime(DateUtil.format(workTicket.getEstimatedEndTime(), "yyyy年MM月dd日 HH时mm分"));

        // 签发信息
        if (CollUtil.isNotEmpty(workFlowlist)) {
            if (status >= TicketStatus.SIGN.getStatus()) {

                Predicate<WorkFlow> predicateNode = f -> ObjectUtil.isNotNull(f.getStatus()) && f.getStatus().equals(TicketStatus.SIGN.getStatus());//过滤节点
                Predicate<WorkFlow> sig = f -> StrUtil.isNotBlank(f.getType()) && f.getType().equals("name0");
                Predicate<WorkFlow> acc = f -> StrUtil.isNotBlank(f.getType()) && f.getType().equals("name1");

                // 签发人
                Optional<WorkFlow> optsig = workFlowlist.stream().filter(predicateNode.and(sig)).findFirst();
                Date sigTime = optsig.map(WorkFlow::getOperationTime).orElse(null);
                yclinesecondprint.setSignPerson(optsig.map(WorkFlow::getName).orElse(""));
                yclinesecondprint.setWorksignTime(DateUtil.format(sigTime, "yyyy年MM月dd日 HH时mm分"));

                // 负责人
                Optional<WorkFlow> optdirector = workFlowlist.stream().filter(predicateNode.and(acc)).findFirst();
                Date directorTime = optdirector.map(WorkFlow::getOperationTime).orElse(null);
                yclinesecondprint.setSignDirectorPerson(optdirector.map(WorkFlow::getName).orElse(""));
                yclinesecondprint.setSignDirectorTime(DateUtil.format(directorTime, "yyyy年MM月dd日 HH时mm分"));
            }
        }

        // 接收
        if (CollUtil.isNotEmpty(workFlowlist)) {
            if (status >= TicketStatus.ACCEPT.getStatus()) {

                Predicate<WorkFlow> predicateNode = f -> ObjectUtil.isNotNull(f.getStatus()) && f.getStatus().equals(TicketStatus.ACCEPT.getStatus());//过滤节点
                Predicate<WorkFlow> memberpre = f -> StrUtil.isNotBlank(f.getType()) && f.getType().equals("name0") ;//工作班组人员签名
                Predicate<WorkFlow> accStartPerson = f -> StrUtil.isNotBlank(f.getType()) && f.getType().equals("name1") ;//开始时间负责人
                Predicate<WorkFlow> accEndPerson = f -> StrUtil.isNotBlank(f.getType()) && f.getType().equals("name2") ;//完成时间负责人

                // 班组
                String memberPerson = workFlowlist.stream().filter(predicateNode.and(memberpre)).map(WorkFlow::getName).collect(Collectors.joining(","));
                yclinesecondprint.setWorkMemberStr(memberPerson);

                // 开始时间
                yclinesecondprint.setWorkStartTime(DateUtil.format(ycInfo.getWorkStartTime(), "yyyy年MM月dd日 HH时mm分"));
                Optional<WorkFlow> optAccStartPerson = workFlowlist.stream().filter(predicateNode.and(accStartPerson)).findFirst();
                yclinesecondprint.setAccDirectorPersonStart(optAccStartPerson.map(WorkFlow::getName).orElse(""));

                // 完成时间
                yclinesecondprint.setWorkEndTime(DateUtil.format(ycInfo.getWorkEndTime(), "yyyy年MM月dd日 HH时mm分"));
                Optional<WorkFlow> optAccEndPerson = workFlowlist.stream().filter(predicateNode.and(accEndPerson)).findFirst();
                yclinesecondprint.setAccDirectorPersonEnd(optAccEndPerson.map(WorkFlow::getName).orElse(""));

            }
        }

        // 工作票终结
        if (CollUtil.isNotEmpty(workFlowlist)) {
            if (status >= TicketStatus.TICKET_END.getStatus()) {

                Predicate<WorkFlow> predicateNode = f -> ObjectUtil.isNotNull(f.getStatus()) && f.getStatus().equals(TicketStatus.TICKET_END.getStatus());//过滤节点
                Predicate<WorkFlow> endfzr = f -> StrUtil.isNotBlank(f.getType()) && f.getType().equals("name0") ;//工作负责人签名
                Predicate<WorkFlow> endxkr = f -> StrUtil.isNotBlank(f.getType()) && f.getType().equals("name1") ;//工作许可人签名

                Optional<WorkFlow> endfzropt = workFlowlist.stream().filter(predicateNode.and(endfzr)).findFirst();
                yclinesecondprint.setTicketEndDirectorPerson(endfzropt.map(WorkFlow::getName).orElse(""));
                Date endfzrtime = endfzropt.map(WorkFlow::getOperationTime).orElse(null);
                yclinesecondprint.setTicketEndworksignTime(DateUtil.format(endfzrtime, "yyyy年MM月dd日 HH时mm分"));

                Optional<WorkFlow> endxkropt = workFlowlist.stream().filter(predicateNode.and(endxkr)).findFirst();
                yclinesecondprint.setTicketEndPermitPerson(endxkropt.map(WorkFlow::getName).orElse(""));
                Date endxkrtime = endxkropt.map(WorkFlow::getOperationTime).orElse(null);
                yclinesecondprint.setTicketEndPermitTime(DateUtil.format(endxkrtime, "yyyy年MM月dd日 HH时mm分"));

            }
        }

        // 工作内容
        List<YcContentBean> ycInfolist = yccontentservice.getYcInfolist(factory, ticketId);
        if (CollUtil.isNotEmpty(ycInfolist)) {
            for (YcContentBean ycContentBean : ycInfolist) {
                YcLineSecondPrint centenPrintbean = new YcLineSecondPrint();
                BeanUtil.copyProperties(yclinesecondprint, centenPrintbean);
                centenPrintbean.setEquipmentName(ycContentBean.getEquipmentName());
                centenPrintbean.setLocationName(ycContentBean.getLocationName());
                centenPrintbean.setContent(ycContentBean.getContent());
                printlist.add(centenPrintbean);
            }
        }


        return printlist;
    }
}
